package kr.co.redbean.controls
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;
	
	import kr.co.redbean.events.MenuEvent;
	
	public class MenuButton extends Sprite
	{
		private var _textField:TextField;
		private var _textFormat:TextFormat;
		private var _menuColor:uint;
		private var _overColor:uint = 0x925555;
		protected var _text:String;
		
		public function MenuButton(text:String)
		{
			super();
			_textFormat = new TextFormat("HelveticaNeue");
			_textField = new TextField;
			_textField.text = text;
			
			addEventListener(MouseEvent.ROLL_OVER, ROLL_OVER);
			addEventListener(MouseEvent.ROLL_OUT, ROLL_OUT);
			addEventListener(MouseEvent.CLICK, MENU_CLICK);
		}
		
		internal function setFormat():void {
			_textFormat.color = _menuColor;
//			_textField.defaultTextFormat = _textFormat;
			_textField.antiAliasType = AntiAliasType.ADVANCED;
			_textField.autoSize = TextFieldAutoSize.LEFT;
			_textField.embedFonts = true;
			_textField.setTextFormat(_textFormat);
			
			addChild(_textField);
		}

		internal function MENU_CLICK($e:MouseEvent):void {
			stage.dispatchEvent(new MenuEvent(MenuEvent.MENU_CLICK, $e.target.text));
		}
		
		private function ROLL_OVER($e:MouseEvent):void {
			Mouse.cursor = MouseCursor.BUTTON;
			_textFormat.color = _overColor;
			_textField.setTextFormat(_textFormat);
		}

		private function ROLL_OUT($e:MouseEvent):void {
			Mouse.cursor = MouseCursor.ARROW;
			_textFormat.color = _menuColor;
			_textField.setTextFormat(_textFormat);
		}

		public function get textField():TextField
		{
			return _textField;
		}

		public function set textField(value:TextField):void
		{
			_textField = value;
		}

		internal function get overColor():uint
		{
			return _overColor;
		}

		internal function set overColor(value:uint):void
		{
			_overColor = value;
		}

		internal function get menuColor():uint
		{
			return _menuColor;
		}

		internal function set menuColor(value:uint):void
		{
			_menuColor = value;
		}

		internal function get textFormat():TextFormat
		{
			return _textFormat;
		}

		internal function set textFormat(value:TextFormat):void
		{
			_textFormat = value;
		}


	}
}